package com.simple.piger.utils;


import com.simple.piger.constant.AjaxCode;
import lombok.Data;

/**
 * Ajax返回固定实体
 * @Author  donghj
 * @Date    2017/11/16 13:45
 */
@Data
public class AjaxResult<T> {

    private int code;
    private String msg;
    private int count;
    private T data;
    public boolean success() {
        return this.code == 200;
    }
    public boolean fail() {
        return !success();
    }
    public AjaxResult(int code, String message, int total, T data) {
        this.code = code;
        this.msg = message;
        this.count = total;
        this.data = data;
    }

    public AjaxResult(int code, String message, T data) {
        this.code = code;
        this.msg = message;
        this.data = data;
    }

    public AjaxResult(int code, String message) {
        this.code = code;
        this.msg = message;
    }

    public AjaxResult(AjaxCode ajaxCode) {
        this.code = ajaxCode.code;
        this.msg = ajaxCode.message;
    }

    public AjaxResult(AjaxCode ajaxCode, T data) {
        this.code = ajaxCode.code;
        this.msg = ajaxCode.message;
        this.data = data;
    }

    public AjaxResult(AjaxCode ajaxCode, String msg) {
        this.code = ajaxCode.code;
        this.msg = msg;
    }
}